package com.net.xpay.core.utils;

import com.google.common.base.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class EncodingUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(EncodingUtil.class);

    public EncodingUtil() {
    }

    public static String getUrlDecodedString(String str, String encoding) {
        if (Strings.isNullOrEmpty(str)) {
            return str;
        } else {
            try {
                return URLDecoder.decode(str, encoding);
            } catch (UnsupportedEncodingException var3) {
                LOGGER.warn("decode string |" + str + " | " + encoding + " | failed");
                throw new RuntimeException("getUrlDecodedString error|" + str);
            }
        }
    }

    public static String getUrlEncodedString(String str, String encoding) {
        if (Strings.isNullOrEmpty(str)) {
            return str;
        } else {
            try {
                return URLEncoder.encode(str, encoding);
            } catch (UnsupportedEncodingException var3) {
                LOGGER.warn("decode string |" + str + " | " + encoding + " | failed");
                throw new RuntimeException("getUrlEncodedString error|" + str);
            }
        }
    }
}
